<template>
    <el-dialog class="dialog" :destroy-on-close="true" :title="title" :visible.sync="isShow" :close-on-click-modal="false"
        @close="onDialogClose">
        <el-form ref="form" label-width="auto" class="form" :model="formData" :rules="rules">
            <el-form-item label="门禁厂商" prop="door_gyscode">
                <el-select v-model="formData.door_gyscode" placeholder="请选择门禁厂商">
                    <el-option v-for="item in doorGysCodeData" :key="item.value" :label="item.label"
                        :value="item.value"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="门禁GUID" prop="door_guid">
                <el-input :readonly="isEdit" v-model="formData.door_guid" placeholder="请输入门禁GUID" maxlength="32"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="onDialogClose">取消</el-button>
            <el-button type="primary" @click="onSubmit">确认</el-button>
        </div>
    </el-dialog>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator"; //, Prop
import { Action, State } from "vuex-class";
import { mixinDialogForm } from "@/mixin/dialog/Form";
import uxInputTree from "@/components/input/tree";
@Component({
    mixins: [mixinDialogForm],
    components: { uxInputTree }
})
export default class equipmentManageDoorEdit extends Vue {
    // 新增
    @Action("equipmentDoor/manageadd") itemAdd: any;
    // 编辑
    @Action("equipmentDoor/manageedit") itemEdit: any;
    @State((state) => state.sharing.netType) doorNetData: any;
    @State((state) => state.sharing.doorGysCode) doorGysCodeData: any;
    editInit(data: any) {
        const me = this as any;
        data.line_way = data.line_way.toString();
        me.formData = Object.assign({}, me.formData, data);
    }
    // 表单数据
    formData: any = {
        line_way: "2",
        door_gyscode: "zxzl",
        door_guid: ""
    };

    /**
     * 校验配置
     *
     * @type {*}
     * @memberof mixinViewRules
     */
    rules: any = {
        line_way: [
            {
                required: true,
                message: "请选择设备联网",
                trigger: "blur"
            }
        ],
        door_guid: [
            {
                required: true,
                message: "请输入门禁编号",
                trigger: "blur"
            }
        ]

    };

    // 获取全部
    @Action("equipmentDoor/all") getAll: any;
    successAfter() {
        // 刷新列表
        this.getAll(true);
    }
    // 标题
    get title() {
        const title = (this as any).isEdit ? "编辑" : "新增";
        return `${title}门禁`;
    }
}
</script>
